package legoproject;

import legoproject.Behaviors.*;
import lejos.nxt.LCD;
import lejos.nxt.Sound;

public class NXTReporter implements StatusReporter {

    private int[] instr = lejos.nxt.Sound.FLUTE;
    private int[] stats = new int[]{-99,-99,-99,-99,-99,-99};
    private String[] statsNames = new String[]{"","","","","",""};

    public synchronized void updateLCD(){
        LCD.clear();
        LCD.drawString(statsNames[0],0,0);
        LCD.drawString(statsNames[1],0,1);
        LCD.drawString(statsNames[2],0,2);
        LCD.drawString(statsNames[3],0,3);
        LCD.drawString(statsNames[4],0,4);
        LCD.drawString(statsNames[5],0,5);
        LCD.drawInt(stats[0], 13, 0);
        LCD.drawInt(stats[1], 13, 1);
        LCD.drawInt(stats[2], 13, 2);
        LCD.drawInt(stats[3], 13, 3);
        LCD.drawInt(stats[4], 13, 4);
        LCD.drawInt(stats[5], 13, 5);
        LCD.refresh();
    }



    public synchronized void behaviorChange(Behavior newBehavior, Behavior oldBehavior) {
        /*if (newBehavior instanceof AvoidEdge) {
            lejos.nxt.Sound.playNote(instr, 440, 100);
            lejos.nxt.Sound.playNote(instr, 880, 100);
        }
        else if (newBehavior instanceof RandomDrive) {
            lejos.nxt.Sound.playNote(instr, 880, 100);
            lejos.nxt.Sound.playNote(instr, 440, 100);
        }
        else if (newBehavior instanceof ShutdownSystem) {
            lejos.nxt.Sound.playNote(instr, 300, 200);
        }
        else if (newBehavior instanceof PickUpGarbage) {
            lejos.nxt.Sound.playNote(instr, 600, 66);
            lejos.nxt.Sound.playNote(instr, 800, 66);
            lejos.nxt.Sound.playNote(instr, 1000, 66);
        }*/

        if (newBehavior instanceof HomingLineAndLight && !(oldBehavior instanceof HomingLineAndLight)) {
            lejos.nxt.Sound.playNote(instr, 600, 66);
            lejos.nxt.Sound.playNote(instr, 1000, 66);
            lejos.nxt.Sound.playNote(instr, 600, 66);
        }
    }

    public synchronized void executingInstruction(int type, int arg1, int arg2) {
        //maybe play a sound here
    }

    public synchronized void sendingBTCommand(int command) {
       // lejos.nxt.Sound.playNote(instr, 990, 150);
    }

    public synchronized void error(int error) {
        if (error == 2){
            lejos.nxt.Sound.playNote(instr, 600, 66);
        }
        else if (error != 0) {
            lejos.nxt.Sound.buzz();
        }
        else {
            lejos.nxt.Sound.beepSequenceUp();
        }

    }

    public synchronized void ready() {
        lejos.nxt.Sound.playNote(instr, 990, 100);
        lejos.nxt.Sound.playNote(instr, 590, 100);
        lejos.nxt.Sound.playNote(instr, 990, 100);

    }

    public synchronized void executingCommand(int type){}

    /**
     * stat numbers go from 0 to 5
     * @param number
     * @param name
     */
    public synchronized void nameStat(int number, String name){
        statsNames[number] = name;
    }

    public synchronized void updateStat(int number, int value){
        stats[number] = value;
    }
}


